feat: add retry mechanism to auto_loop click steps#55
feat: add retry mechanism to auto_loop click steps#55peach322 wants to merge 1 commit intoAliceJump:masterfrom
Conversation
Agent-Logs-Url: https://github.com/peach322/ok-gf2/sessions/99d7e04a-75ea-4c08-936a-2cd3e1c0106e Co-authored-by: peach322 <268908037+peach322@users.noreply.github.com>
📝 WalkthroughWalkthroughThe changes add retry-capable logic to the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/tasks/DailyTask.py (1)
508-513: Scope"确认"OCR to a stable region to avoid false retries.Step 3 and step 5 use
match=["确认"]withoutbox. The disappearance check then scans the full screen, so unrelated"确认"text can keep triggering retries/failure.🔧 Proposed refactor
def auto_loop(self): + confirm_box = self.box.bottom_right # adjust to the actual confirm area if needed + # 步骤 1: 点击"自主循环",带重试 if not self._auto_loop_step_with_retry( step_num=1, match=[re.compile("自主循环")], box=self.box.bottom_left, @@ if not self._auto_loop_step_with_retry( step_num=3, match=["确认"], + box=confirm_box, settle_time=2, after_sleep=2, ): return @@ if not self._auto_loop_step_with_retry( step_num=5, match=["确认"], + box=confirm_box, settle_time=2, after_sleep=2, ): returnAlso applies to: 524-529
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/tasks/DailyTask.py` around lines 508 - 513, The OCR match for "确认" in calls to _auto_loop_step_with_retry (used for step_num=3 and the similar call around step_num=5) currently scans the full screen and can pick up unrelated "确认" text; update both calls to pass a stable box parameter (pixel or normalized rect) that confines OCR to the dialog/button area where the confirmation appears, e.g. add box=<appropriate_rect> to the _auto_loop_step_with_retry invocation so disappearance checking only scans that region and avoids false retries/failures.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/tasks/DailyTask.py`:
- Around line 462-464: The added Chinese docstrings/comments in
src/tasks/DailyTask.py use fullwidth punctuation (e.g., fullwidth
commas/periods/quotes) which triggers Ruff confusable-character warnings
(RUF001/RUF002/RUF003); fix by normalizing those punctuation characters to ASCII
equivalents in the affected docstrings/comments (the docstring block around the
OCR click behavior and the subsequent comment blocks you added) or, if localized
fullwidth punctuation is intentional, append a per-line or per-block Ruff noqa
comment (e.g., # noqa: RUF001,RUF002,RUF003) to those specific
docstrings/comments so Ruff stops flagging them. Ensure you update the same text
blocks mentioned in the review (the OCR/docstring and the other nearby comment
blocks) rather than changing unrelated code.
- Around line 466-473: The retry loop currently returns immediately on the first
falsy result from wait_click_ocr, skipping remaining attempts; change the logic
in the loop that iterates "for attempt in range(3)" so that when
wait_click_ocr(...) returns falsy you log the attempt failure (using
self.log_info and step_num) and continue to the next iteration instead of
returning False, and after the loop completes (if all attempts fail) return
False once—this preserves retries for transient OCR misses while keeping the
final failure behavior.
---
Nitpick comments:
In `@src/tasks/DailyTask.py`:
- Around line 508-513: The OCR match for "确认" in calls to
_auto_loop_step_with_retry (used for step_num=3 and the similar call around
step_num=5) currently scans the full screen and can pick up unrelated "确认" text;
update both calls to pass a stable box parameter (pixel or normalized rect) that
confines OCR to the dialog/button area where the confirmation appears, e.g. add
box=<appropriate_rect> to the _auto_loop_step_with_retry invocation so
disappearance checking only scans that region and avoids false retries/failures.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 3054bc37-70ac-4e2e-9b83-80d31412a3ea
📒 Files selected for processing (1)
src/tasks/DailyTask.py
| """ | ||
| 点击OCR匹配元素,等待点击特征在 3s 内消失。 | ||
| 若特征未消失则重试,最多尝试 3 次。 |
There was a problem hiding this comment.
Ruff confusable-character warnings are present in newly added text.
The new docstrings/comments/strings contain fullwidth punctuation flagged by Ruff (RUF001/RUF002/RUF003). If lint is gating, normalize punctuation or add an explicit rule exception for localized Chinese text.
Also applies to: 471-473, 482-483, 487-497, 507-523
🧰 Tools
🪛 Ruff (0.15.12)
[warning] 463-463: Docstring contains ambiguous , (FULLWIDTH COMMA). Did you mean , (COMMA)?
(RUF002)
[warning] 464-464: Docstring contains ambiguous , (FULLWIDTH COMMA). Did you mean , (COMMA)?
(RUF002)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/tasks/DailyTask.py` around lines 462 - 464, The added Chinese
docstrings/comments in src/tasks/DailyTask.py use fullwidth punctuation (e.g.,
fullwidth commas/periods/quotes) which triggers Ruff confusable-character
warnings (RUF001/RUF002/RUF003); fix by normalizing those punctuation characters
to ASCII equivalents in the affected docstrings/comments (the docstring block
around the OCR click behavior and the subsequent comment blocks you added) or,
if localized fullwidth punctuation is intentional, append a per-line or
per-block Ruff noqa comment (e.g., # noqa: RUF001,RUF002,RUF003) to those
specific docstrings/comments so Ruff stops flagging them. Ensure you update the
same text blocks mentioned in the review (the OCR/docstring and the other nearby
comment blocks) rather than changing unrelated code.
| for attempt in range(3): | ||
| result = self.wait_click_ocr( | ||
| match=match, box=box, time_out=time_out, after_sleep=0, log=True, **kwargs | ||
| ) | ||
| if not result: | ||
| self.log_info(f"自主循环步骤{step_num}未完成,退出循环", notify=True) | ||
| return False | ||
| # 等待最多 3s,检测点击特征是否消失 |
There was a problem hiding this comment.
Retry loop exits on first OCR miss, so retries are skipped.
When wait_click_ocr returns falsy, the function returns immediately instead of trying remaining attempts. This bypasses retry behavior for transient OCR misses.
🔧 Proposed fix
for attempt in range(3):
result = self.wait_click_ocr(
match=match, box=box, time_out=time_out, after_sleep=0, log=True, **kwargs
)
if not result:
- self.log_info(f"自主循环步骤{step_num}未完成,退出循环", notify=True)
- return False
+ if attempt < 2:
+ self.log_info(
+ f"自主循环步骤{step_num}未识别到目标,重试 ({attempt + 2}/3)",
+ notify=True
+ )
+ continue
+ self.log_info(f"自主循环步骤{step_num}未完成,退出循环", notify=True)
+ return False📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| for attempt in range(3): | |
| result = self.wait_click_ocr( | |
| match=match, box=box, time_out=time_out, after_sleep=0, log=True, **kwargs | |
| ) | |
| if not result: | |
| self.log_info(f"自主循环步骤{step_num}未完成,退出循环", notify=True) | |
| return False | |
| # 等待最多 3s,检测点击特征是否消失 | |
| for attempt in range(3): | |
| result = self.wait_click_ocr( | |
| match=match, box=box, time_out=time_out, after_sleep=0, log=True, **kwargs | |
| ) | |
| if not result: | |
| if attempt < 2: | |
| self.log_info( | |
| f"自主循环步骤{step_num}未识别到目标,重试 ({attempt + 2}/3)", | |
| notify=True | |
| ) | |
| continue | |
| self.log_info(f"自主循环步骤{step_num}未完成,退出循环", notify=True) | |
| return False | |
| # 等待最多 3s,检测点击特征是否消失 |
🧰 Tools
🪛 Ruff (0.15.12)
[warning] 471-471: String contains ambiguous , (FULLWIDTH COMMA). Did you mean , (COMMA)?
(RUF001)
[warning] 473-473: Comment contains ambiguous , (FULLWIDTH COMMA). Did you mean , (COMMA)?
(RUF003)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/tasks/DailyTask.py` around lines 466 - 473, The retry loop currently
returns immediately on the first falsy result from wait_click_ocr, skipping
remaining attempts; change the logic in the loop that iterates "for attempt in
range(3)" so that when wait_click_ocr(...) returns falsy you log the attempt
failure (using self.log_info and step_num) and continue to the next iteration
instead of returning False, and after the loop completes (if all attempts fail)
return False once—this preserves retries for transient OCR misses while keeping
the final failure behavior.
Agent-Logs-Url: https://github.com/peach322/ok-gf2/sessions/99d7e04a-75ea-4c08-936a-2cd3e1c0106e
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes